<template>
    <div class="detail">
        <header>详情页头</header>
        <div class="detail_content">
            <!-- 轮播 -->
            <LunCom :banners="banners"></LunCom>
            <!-- 产品详情 -->
            <ProInfo :proname="proname" :originprice="originprice"></ProInfo>
            <!-- 地址选择 -->
            <AddressCom></AddressCom>
            <!-- 猜你喜欢 -->
            <!-- 加入购物粗 -->
            <van-action-bar>
                <van-action-bar-icon icon="chat-o" text="客服" dot />
                <van-action-bar-icon icon="cart-o" text="购物车" badge="5" />
                <van-action-bar-icon icon="shop-o" text="店铺" badge="12" />
                <van-action-bar-button type="warning" text="加入购物车" @click="addToCart" />
                <van-action-bar-button type="danger" text="立即购买" />
            </van-action-bar>
        </div>
    </div>
</template>

<script>
import { getDetailPro } from '@/apis/home';
import LunCom from './components/LunCom.vue';
import ProInfo from './components/ProInfo.vue';
import AddressCom from './components/AddressCom.vue';
import { doAddCart } from '@/apis/cart';
export default {
    data() {
        return {
            banners: [],
            proname: "",
            desc: "",
            originprice: 6499,
            userid: ''
        }
    },
    created() {
        this.userid = localStorage.getItem("userid")
        getDetailPro(this.$route.params.proid).then(res => {
            this.banners = res.data.data.banners[0].split(",")
        })
    },
    methods: {
        addToCart() {
            doAddCart({ userid: this.userid ,proid:this.$route.params.proid,num:1}).then(res=>{
                if(res.data.code!='200')return showToast("加入购物车失败")
                showToast("加入购物车成功")
                 this.$router.push("/cart")
            })
        }
    },
    components: {
        LunCom,
        ProInfo,
        AddressCom
    }
}
</script>

<style scoped></style>